#include "D:\Documentos\Master In Mechatronics\2nd Semester\Computer Science\Laboratory\CS Laboratory\CS_ACUAS\ACUAS/ACUAS.h"
#include <avr/io.h>
#include "D:\Documentos\Master In Mechatronics\2nd Semester\Computer Science\Laboratory\CS Laboratory\CS_ACUAS\ACUAS/ACUASLCD-CSlab.h"	



unsigned char shuffle (void);


unsigned char last_name[52]={'A','2','3','4','5','6','7','8','9','0','J','Q','K','A','2','3','4','5','6','7','8','9','0','J','Q','K','A','2','3','4','5','6','7','8','9','0','J','Q','K','A','2','3','4','5','6','7','8','9','0','J','Q','K'};

unsigned char last_type[52]={'c','c','c','c','c','c','c','c','c','c','c','c','c','s','s','s','s','s','s','s','s','s','s','s','s','s','h','h','h','h','h','h','h','h','h','h','h','h','h','d','d','d','d','d','d','d','d','d','d','d','d','d'};

unsigned char card=0;


int main(void)
{
	unsigned char finished=0;
	RANDOM_INIT

while(1)
{

	
  do
{
	 finished=shuffle();
}
while(finished!=1);


	}//end while
}



unsigned char shuffle (void)
{
unsigned char next_card=0,already=0;

int j=0,i=0;

unsigned char card_new_position[52]={0},new_name[52]={0},new_type[52]={0};

	next_card=RANDOM(1,52);
	next_card=next_card-1;

	while(j<52)
	{
		while(new_name[i]!=0)
		{
			if (next_card==card_new_position[i])
			already=1;
		i++;
		}//end while check
		i=0;
			if(already==0)
			{
				new_name[j]=last_name[next_card];
				new_type[j]=last_type[next_card];

				card_new_position[j]=next_card;
					next_card=RANDOM(1,52);
					next_card=next_card-1;
					j++;
					//return 0;
			}
			else
				{	
				next_card=RANDOM(1,52);
				next_card=next_card-1;
				already=0;
			//	return 0;
				}


	}//end main while
	
	for(i=0;i<52;i++)
	{
	last_name[i]=new_name[i];
	last_type[i]=new_type[i];
	}

for(i=0;i<52;i++)
	{
	new_name[i]=0;
	new_type[i]=0;
	}
	
	return 1;
}
